在 Git 中,通过分支实现并行开发。正式地说, 分支是一条独立的开发线 它从主时间线上分叉出来。这使得多个工作路径可以作为 内部对象 共存,而不会影响主代码库的稳定性。
1. 初生状态:主分支
每个仓库都以一个默认分支开始,称为 master。这是 Git 的默认分支。当你运行 git branch 来列出所有分支时,其旁边的 星号 (*) 表示当前检出的环境——即你正在使用的活跃开发世界。
2. 功能分支
虽然有些分支生命周期较短,但一个 功能分支 是一种更长期存在的主题分支,专门用于开发特定功能。它将‘进行中’的代码与已准备就绪的‘主分支’隔离。
类比: 把主分支想象成摩天大楼的设计蓝图。为了测试太阳能板,你可以使用透明图层(功能分支)。你可以在图层上自由试验和犯错,而永远不会危及原始蓝图的完整性。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Which command is used to list all branches in a Git repository?
git list
git branch
git checkout --list
git show-branches
✅ Correct!
Correct! Running 'git branch' displays all local branches in the current repository.❌ Incorrect
The command 'git branch' is the standard utility for listing, creating, and deleting branches.QUESTION 2
What does the asterisk (*) next to a branch name in the branch list signify?
The branch has uncommitted changes.
The branch is protected and cannot be deleted.
The branch is currently checked out (active).
The branch is the newest one created.
✅ Correct!
Exactly. The asterisk indicates your current location (HEAD) within the project's development universes.❌ Incorrect
The asterisk is a status marker indicating which branch is 'active' or 'checked out'.QUESTION 3
How is a 'feature branch' defined in Git development?
A branch that only contains CSS files.
A temporary branch that is never merged.
A longer-running topic branch for a specific functionality.
The branch where all bugs are fixed globally.
✅ Correct!
Yes! Feature branches are used to isolate specific tasks until they are ready for the main codebase.❌ Incorrect
Feature branches are intended for developing specific features in isolation from the main timeline.QUESTION 4
What is the name of Git's default development branch?
mainline
trunk
master
root
✅ Correct!
Correct. 'master' is the default name Git assigns to the first branch created in a repository.❌ Incorrect
While some modern platforms use 'main', Git's internal default and the focus of this tutorial is 'master'.QUESTION 5
True or False: A branch is considered an 'internal object' that tracks specific changes.
True
False
✅ Correct!
True. Branches are abstractions—internal pointers to commits that allow for parallel development.❌ Incorrect
Git manages branches as internal references (pointers) to specific points in the commit history.Architectural Design Simulation
Managing Parallel Blueprints
You are leading a project to design a skyscraper. You have the 'master' blueprints finalized up to the 50th floor. Your client wants to see two options: a rooftop garden and a rooftop helipad. You decide to use Git branching logic to handle this request.
Q
If you create a branch for the 'rooftop-garden', what happens to the 'master' blueprints while you work on the garden design?
Solution:
The master blueprints remain unchanged and stable. The garden design exists in an independent line of development, ensuring the original project history is not compromised.
The master blueprints remain unchanged and stable. The garden design exists in an independent line of development, ensuring the original project history is not compromised.
Q
Which specific branch type would the 'rooftop-garden' be categorized as?
Solution:
It would be a feature branch (or topic branch), created with the intention of developing a specific piece of functionality (the garden) in isolation.
It would be a feature branch (or topic branch), created with the intention of developing a specific piece of functionality (the garden) in isolation.
Q
How would you verify which 'blueprint' (branch) you are currently drawing on using the Git CLI?
Solution:
You would use the 'git branch' command. The branch name with the asterisk (*) next to it represents the currently checked-out environment.
You would use the 'git branch' command. The branch name with the asterisk (*) next to it represents the currently checked-out environment.